<?php

namespace app\ru\controller;

use app\common\controller\Frontend;
use think\Db;
class About extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function _initialize()
    {
        parent::_initialize();

        $param = $this->request->param();
        $lanmu = isset($param['lanmu'])?$param['lanmu']:null;
        $id = isset($param['id'])?$param['id']:null;
        
        $erlist = Db::name('about')->where('status',$lanmu)->order('weigh','desc')->order('id','desc')->select();


        $this->lanmu = $lanmu;
        $this->id = $id;

        $this->view->assign('lanmu', $lanmu);
        $this->view->assign('id', $id);
        $this->view->assign('erlist', $erlist);

    }

    public function index()
    {
        $lanmu = $this->lanmu;
        $id = $this->id;


        if($lanmu==2){
            if($id == null){
                //简介
                $show['jianjie'] = Db::name('about')->where('id',5)->find();
                $show['jianjie']["content"] = strip_tags(str_replace("&nbsp;","",htmlspecialchars_decode($show['jianjie']["content"])));
                $show['jianjie']['video'] = Db::name('danye')->where('id',17)->find();
                
                //荣誉
                $show['honor']['show'] = Db::name('about')->where('id',4)->find();
                $show['honorlist'] = Db::name('productslist')->where('productstype','in',get_ertypeid_by_lanmu(14))->where('shswitch',1)->order('weigh','desc')->order('id','desc')->select();
                
                //可持续发展
                $show['cxfz']['show'] = Db::name('about')->where('id',3)->find();
                $show['cxfz']['con'] = Db::name('about')->where('status',15)->order('weigh','desc')->order('id','desc')->select();
                
                //合作伙伴
                $show['hzhb']['show'] = Db::name('about')->where('id',2)->find();
                $list = Db::name('productslist')->where('productstype','in',get_ertypeid_by_lanmu(17))->where('shswitch',1)->order('weigh','desc')->order('id','desc')->select();
                $i=0;
                $show['hzhb']['list'][0] = array();
                foreach ($list as $key => $value) {
                    if( count($show['hzhb']['list'][$i])>=9 ){
                        $i++;
                    }
                    $show['hzhb']['list'][$i][] = $value;
                }

                //新闻中心
                $show['news']['show'] = Db::name('about')->where('id',1)->find();
                $show['news']['list'] = Db::name('newslist')->where('newstype','in',get_ertypeid_by_lanmu(18))->where('shswitch',1)->order('weigh','desc')->order('id','desc')->select();

                $this->view->assign('show', $show);
                return $this->view->fetch();

            }else if($id==5){
                //简介
                $show = Db::name('about')->where('id',$id)->find();
                $show['video'] = Db::name('danye')->where('id',17)->find();
                $this->view->assign('show', $show);

                return $this->view->fetch('jianjie');

            }else if($id==4){
                //荣誉
                $param = $this->request->param();
                $cid = isset($param['cid'])?$param['cid']:null;

                $show = Db::name('about')->where('id',$id)->find();
                $show['erlist'] = Db::name('productstype')->where('status',14)->order('weigh','desc')->order('id','desc')->select();

                if(!$cid){
                    $cid = $show['erlist'][0]['id'];
                }

                $show['list'] = Db::name('productslist')->where('productstype',$cid)->where('shswitch',1)->order('weigh','desc')->order('id','desc')->paginate(8);
                
                $this->view->assign('show', $show);
                $this->view->assign('cid', $cid);
                return $this->view->fetch('honor');

            }else if($id==3){
                //可持续发展
                $show = Db::name('about')->where('id',$id)->find();
                $show['list'] = Db::name('productslist')->where('productstype','in',get_ertypeid_by_lanmu(16))->where('shswitch',1)->order('weigh','desc')->order('id','desc')->select();

                foreach ($show['list'] as $key => $value) {
                    $show['list'][$key]['arr'] = explode(',',$value['images_ru']);
                }

                $this->view->assign('show', $show);
                return $this->view->fetch('cxfz');
                
            }else if($id==2){
                //合作列表
                $show = Db::name('about')->where('id',$id)->find();

                $list = Db::name('productslist')->where('productstype','in',get_ertypeid_by_lanmu(17))->where('shswitch',1)->order('weigh','desc')->order('id','desc')->select();
                $i=0;
                $show['list'][0] = array();
                foreach ($list as $key => $value) {
                    if( count($show['list'][$i])>=9 ){
                        $i++;
                    }
                    $show['list'][$i][] = $value;
                }

                $this->view->assign('show', $show);
                return $this->view->fetch('hzlist');

            }else if($id==1){
                //新闻中心
                $param = $this->request->param();
                $cid = isset($param['cid'])?$param['cid']:null;

                $show = Db::name('about')->where('id',$id)->find();
                $show['erlist'] = Db::name('newstype')->where('status',18)->order('weigh','desc')->order('id','desc')->select();
                if(!$cid){
                    $cid = $show['erlist'][0]['id'];
                }
                $show['list'] = Db::name('newslist')->where('newstype',$cid)->where('shswitch',1)->order('weigh','desc')->order('id','desc')->select();

                $this->view->assign('show', $show);
                $this->view->assign('cid', $cid);
                return $this->view->fetch('aboutnew');

            }else{

                $show = Db::name('about')->where('id',$id)->find();
                $this->view->assign('show', $show);
                return $this->view->fetch('aboutnew');

            }


        }else if($lanmu==6){
            //应用领域

            return $this->view->fetch('yyly');

        }else if($lanmu==8){
            //生产制造
            $show['liucheng'] = Db::name('productslist')->where('productstype','in',get_ertypeid_by_lanmu(24))->where('shswitch',1)->order('weigh','desc')->order('id','desc')->select();

            $show['jianjie1'] = Db::name('danye')->where('id',10)->find();
            $show['jianjie2'] = Db::name('danye')->where('id',11)->find();
            $show['jianjie1sj'] = Db::name('danye')->where('id',19)->find();
            $show['bigimg'] = Db::name('danye')->where('id',12)->find();
            $show['img1'] = Db::name('danye')->where('id',13)->find();
            $show['img2'] = Db::name('danye')->where('id',14)->find();




            $this->view->assign('show', $show);
            return $this->view->fetch('sczz');

        }else if($lanmu==10){
            //质量保证
            $erlist = Db::name('about')->where('status',$lanmu)->order('weigh','desc')->order('id','desc')->select();
            if(!$id){
                $id = $erlist[0]['id'];
            }
            
            $show = Db::name('about')->where('id',$id)->find();

            $show['phsy'] = Db::name('about')->where('status',19)->order('weigh','desc')->order('id','desc')->select();
            $show['fphsy'] = Db::name('about')->where('status',20)->order('weigh','desc')->order('id','desc')->select();
            $show['pz'] = Db::name('newslist')->where('newstype','in',get_ertypeid_by_lanmu(21))->order('weigh','desc')->order('id','desc')->select();
            $show['imglist'] = Db::name('about')->where('status',22)->order('weigh','desc')->order('id','desc')->select();


            $this->view->assign('show', $show);
            $this->view->assign('id', $id);
            return $this->view->fetch('zlbz');

        }else if($lanmu==3){
            //联系我们
            $erlist = Db::name('about')->where('status',$lanmu)->order('weigh','desc')->order('id','desc')->select();
            if(!$id){
                $id = $erlist[0]['id'];
            }
            $this->view->assign('id', $id);

            if($id==12){
                $show = Db::name('about')->where('id',$id)->find();
                $show['ditu'] = Db::name('danye')->where('id',9)->find();
                $this->view->assign('show', $show);
                return $this->view->fetch('contactus');
            }else if($id==11){

                $show['list'] = Db::name('newslist')->where('newstype','in',get_ertypeid_by_lanmu(23))->where('shswitch',1)->order('weigh','desc')->order('id','desc')->select();


                $this->view->assign('show', $show);
                return $this->view->fetch('job');
            }else if($id==10){

                return $this->view->fetch('gbook');

            }else{

                $show = Db::name('about')->where('id',$id)->find();
                $this->view->assign('show', $show);
                return $this->view->fetch('aboutnew');

            }


            

        }





    }



    public function aboutnewshow()
    {

        $param = $this->request->param();
        $cid = isset($param['cid'])?$param['cid']:null;
        $newsid = isset($param['newsid'])?$param['newsid']:null;

        $show = Db::name('newslist')->where('id',$newsid)->find();
        

        $show['prev'] = Db::name('newslist')->where('weigh','>=',$show['weigh'])->where('id','neq',$show['id'])->where('newstype',$cid)->where('shswitch',1)->order('weigh','asc')->order('id','asc')->find();
        $show['next'] = Db::name('newslist')->where('weigh','<=',$show['weigh'])->where('id','neq',$show['id'])->where('newstype',$cid)->where('shswitch',1)->order('weigh','desc')->order('id','desc')->find();

        $this->view->assign('show', $show);
        $this->view->assign('cid', $cid);

        return $this->view->fetch('aboutnewshow');
    }  



    public function addgbook(){
        $param = $this->request->post();
        $name = isset($param['name'])?$param['name']:null;
        $title = isset($param['title'])?$param['title']:null;
        $zuoji = isset($param['zuoji'])?$param['zuoji']:null;
        $chengshi = isset($param['chengshi'])?$param['chengshi']:null;
        $tel = isset($param['tel'])?$param['tel']:null;
        $email = isset($param['email'])?$param['email']:null;
        $address = isset($param['address'])?$param['address']:null;
        $content = isset($param['content'])?$param['content']:null;

        $data['name'] = $name;
        $data['tel'] = $tel;
        $data['email'] = $email;
        $data['address'] = $address;
        $data['content'] = $content;
        $data['chengshi'] = $chengshi;
        $data['zuoji'] = $zuoji;
        $data['title'] = $title;
        $data['createtime'] = time();

        $sql = Db::name('gbooklist')->insert($data);
        if($sql){
            $result['code'] = 1;
        }else{
            $result['code'] = 0;
        }
        return $result;

    }











    
}
